package com.book.scc.controller;

import com.book.scc.pojo.User;
import com.book.scc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login.do")

    public String login(String username, String password, HttpServletRequest request){
        System.out.println("username:"+username+"..."+"password:"+password);
        User user= null;
        user =  userService.login(username,password);
        String url="";
        System.out.println("出来");
        if (user == null) {
            request.setAttribute("condition","用户名或者密码错误");
            url = "forward:index.jsp";
        }else{
            request.setAttribute("username",username);
            url="forward:queryBooks.do";
        }
        return url;
    }
}
